package cn.zc.examination.service.service.impl;

import cn.tools.core.exception.BizException;
import cn.zc.examination.entity.Dto.ExaminationClassifyDto;
import cn.zc.examination.entity.ExaminationClassify;
import cn.zc.examination.service.mapper.ExaminationClassifyMapper;
import cn.zc.examination.service.service.ExaminationClassifyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 考试类别 服务实现类
 * </p>
 *
 * @author keno
 * @since 2022-02-22
 */
@Service
public class ExaminationClassifyServiceImpl extends ServiceImpl<ExaminationClassifyMapper, ExaminationClassify> implements ExaminationClassifyService {

    /**
     * 创建考试类目
     * @param name
     * @return
     */
    @Override
    public ExaminationClassifyDto createExaminationClassify(String name) {
        ExaminationClassify examinationClassify = new ExaminationClassify();
        examinationClassify.setExaminationName(name);
        if(!save(examinationClassify)){
            throw new BizException("创建考试类目失败");
        }
        ExaminationClassifyDto examinationClassifyDto = new ExaminationClassifyDto();
        examinationClassifyDto.setExaminationName(name);
        examinationClassifyDto.setId(examinationClassify.getId());
        return examinationClassifyDto;
    }

    /**
     * 删除考试类目
     * @param id
     */
    @Override
    public void deleteExaminationClassify(String id) {
        if(!removeById(id)){
            throw new BizException("删除考试类目失败");
        }
    }
}
